package code.easylevel;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MthToLastElement {

	public static List<String> dataList  = new ArrayList<String>();
	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader;
		String line;
		File file = new File(args[0]);
		bufferedReader = new BufferedReader(new FileReader(file));
		while((line=bufferedReader.readLine()) != null){
			insertIntoArraylist(line);
			searchMthToLastElement();
			dataList.removeAll(dataList);
		}
		bufferedReader.close();
	}
	
	public static void insertIntoArraylist(String line){
		
		String[] inputParams = line.split("\\s");
		for(int i = 0 ;i<inputParams.length ;i++){
			dataList.add((String)inputParams[i]);
		}	
	}
	
	public static void searchMthToLastElement(){
		if(dataList.size()>0){
			int lastElement = Integer.parseInt(dataList.get(dataList.size()-1));
			if(dataList.size()-(lastElement+1) > -1){
				System.out.println(dataList.get(dataList.size()-(lastElement+1)));	
			}
				
		}
	}

}
